package leetcode;

/**
 * Created by Ghost on 2014/9/30 0030.
 */
public class Search_a_2D_Matrix {
    public static boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length;
        int n = matrix[m-1].length;
        int i;
        for(i=0;i<m && target>=matrix[i][0];i++);
        if(i == 0)
            return false;
        else{
            int j;
            for(j=0;j<n && target!=matrix[i-1][j];j++);
            if(j==n)
                return false;
            else
                return true;
        }
    }
    public static void main(String[] args){

        int[][] matrix = new int[][]{{1,3,5,7},{10,11,16,20},{23,30,34,50}};
        System.out.println(searchMatrix(matrix,0));
    }
}
